﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BusinessLayer.WorldArtPrice.Entities;
using DBHelper;

namespace BusinessLayer.WorldArtPrice
{
    public class SlideShowBL
    {
        private readonly DbHelper _db;

        public SlideShowBL()
        {
            _db = new DbHelper(new DbConfig().DbWorldArtPriceConnectionString);         
        }

        public SlideShow GetTop()
        {
            var oCommand = new SqlCommand("sp_SlideShow_SelectTop") { CommandType = CommandType.StoredProcedure };            

            var list = _db.GetList<SlideShow>(oCommand);
            return list.FirstOrDefault();
        }

        public void Insert(SlideShow slideShow, out int result)
        {
            var oCommand = new SqlCommand("sp_SlideShow_Insert") { CommandType = CommandType.StoredProcedure };
            oCommand.Parameters.Add(new SqlParameter("@TimeWaiting", slideShow.TimeWaiting));
            
            var output = new SqlParameter("@Result", SqlDbType.Int) { Direction = ParameterDirection.Output };
            oCommand.Parameters.Add(output);
            _db.ExecuteNonQuery(oCommand);

            result = (int)output.Value;
        }
    }
}
